set more off
clear all


use ASEC_data.dta

rename asecwt weight
drop if empstat==1 /*drop armed forces, same as in Kendrick*/
drop if hflag==1 /*adjust for redesign in 2014, use a larger proportion (5/8) */

gen flag_above_14=0
replace flag_above_14=1 if age>=14

gen flag_above_20=0
replace flag_above_20=1 if age>=20

gen h=.
replace h=ahrsworkt
replace h=. if ahrsworkt==999

sort year sex
by year sex: egen hours=total(h*weight)
by year sex: egen population=total(weight/1000)
by year sex: egen population_above_14=total(weight*flag_above_14/1000)
by year sex: egen population_above_20=total(weight*flag_above_20/1000)
replace hours=hours/10^6*52
by year sex: gen id=_n
drop if id>1
keep year sex hours population*

reshape wide hours population population_above_14 population_above_20, i(year) j(sex)
local list hours population population_above_14 population_above_20
foreach var of local list {
	rename `var'1 `var'_male
	rename `var'2 `var'_female
	gen `var'=`var'_male+`var'_female
}

save ASEC_hours_population, replace
